package com.yunupmall.service.ford.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunupmall.api.fordVO.CommodityVo;
import com.yunupmall.api.fordVO.KindPo;
import com.yunupmall.api.fordentity.Commodity;
import com.yunupmall.api.fordentity.Kind;
import com.yunupmall.api.fordentity.SpecsCommodity;
import com.yunupmall.api.po.IndexKindCommtityPO;
import com.yunupmall.entity.ford.FordCommodity;
import com.yunupmall.entity.ford.FordCommtoty;
import com.yunupmall.entity.ford.FordSpecsCommodity;
import com.yunupmall.mapper.FordMapper.IndexMapper;
import com.yunupmall.service.admin.service.CommodityService;
import com.yunupmall.service.admin.service.KindService;
import com.yunupmall.service.ford.service.IndexService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class Indeximpl implements IndexService {
    private final KindService kindService;
    private final CommodityService commodityService;
    @Autowired
    IndexMapper indexMapper;

    /**
     * 获取类别信息和商品信息
     * @return
     */
    @Override
    public List<IndexKindCommtityPO> getKindCommtityData() {
        KindPo kindPo = new KindPo();
        kindPo.setDeflag(0);
        List<Kind> list = kindService.getList(kindPo);
        final IndexKindCommtityPO[] indexKindCommtityPO = new IndexKindCommtityPO[1];
        List<IndexKindCommtityPO> indexKindCommtityPOS = new ArrayList<>();
        if (list.size()!=0){
            list.forEach(kind -> {
                CommodityVo commodityVo = new CommodityVo();
                commodityVo.setKindId(kind.getId());
                commodityVo.setStatics(0);
                commodityVo.setPage(1);
                commodityVo.setLimit(10);
                Page<CommodityVo> commodityVoPage = commodityService.pageData(commodityVo);
                if (commodityVoPage.getRecords().size() != 0) {
                    indexKindCommtityPO[0] = new IndexKindCommtityPO();
                    indexKindCommtityPO[0].setId(kind.getId());
                    indexKindCommtityPO[0].setImage(kind.getImage());
                    indexKindCommtityPO[0].setName(kind.getName());
                    indexKindCommtityPO[0].setCommodityList(commodityVoPage.getRecords());
                    indexKindCommtityPOS.add(indexKindCommtityPO[0]);
                }
            });
        }
        return indexKindCommtityPOS;
    }

    @Override
    public List<Kind> fordquertykind() {
        return indexMapper.fordquertykind();
    }

    @Override
    public List<FordCommtoty> getCommtityData(Integer id) {
        return indexMapper.getCommtityData(id);
    }

    @Override
    public List<FordCommodity> getcommtotyimage(Integer id) {
        return indexMapper.getcommtotyimage(id);
    }

    @Override
    public FordCommodity getcomData(Integer id) {
        return indexMapper.getcomData(id);
    }

    @Override
    public List<SpecsCommodity> getskuspecs(Integer c_id) {
        return indexMapper.getskuspecs(c_id);
    }

    @Override
    public FordSpecsCommodity queryspecsskudata(Integer id) {
        return indexMapper.queryspecsskudata(id);
    }


}
